package zsc.ruanc.practicaltraining.utils;


import zsc.ruanc.practicaltraining.exception.ApiException;


import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class DataVerificationUtils {
    public static boolean isEmail(String email) {
        if (null==email || "".equals(email)){
            throw new ApiException(400);
        }
        String regEx1 = "^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*\\.[a-zA-Z0-9]{2,6}$";
        Pattern p = Pattern.compile(regEx1);
        Matcher m = p.matcher(email);
        if(m.matches()){
            return true;
        }else{
            throw new ApiException(400);
        }
    }

    public static boolean isCode(Integer code) {
        if (null == code) {
            throw new ApiException(400);
        }
        if (code < 1000 || code >= 10000) {
            throw new ApiException(400);

        }
        return true;
    }
}
